home *** CD-ROM | disk | FTP | other *** search
- Path: mojo.eng.umd.edu!usenet
- From: Vinay Chande <chande@eng.umd.edu>
- Newsgroups: comp.lang.c++
- Subject: help! machine dependent behavior of libg++ iofstream functions
- Date: Tue, 02 Apr 1996 23:56:47 -0500
- Organization: Department of Electrical Engineering, University of Maryland, College Park.
- Message-ID: <3162050F.41C6@eng.umd.edu>
- NNTP-Posting-Host: baud.eng.umd.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; OSF1 V3.2 alpha)
-
- Subject:
- help! machine dependent behavior of libg++ fstream functions.
-
- Please help.
-
- I have two files Write.cxx and Read.cxx containing the
- following.
-
- --------------
- //Write.cxx
-
- #include<fstream.h>
- main()
- {
- int a = 0x12abcd34;
- ofstream outstream("data/junk");
- outstream.write(&a, sizeof(int));
- outstream.close();
-
- }
-
- ------------------------------
-
- // Read.cxx
- #include<fstream.h>
- #include<stream.h>
- main()
- {
- int a;
- ifstream instream("data/junk");
- instream.read(&a, sizeof(int));
- instream.close();
-
- cout << "a is " << hex(a) <<endl;
-
-
- }
-
- -- -----------
-
- I compile both of them using g++.
-
- I run Write.cxx on a sun machine and create the file "data/junk".
- I run Read.cxx on a DEC alpha.
-
- You guessed it. Read operation yields
-
- a is 34cdab12
-
- (The byte order is reversed.)
-
- Same thing happens if I reverse machines for reading and writing.
- (If both programs are run on same machine, the result is always
- correct.)
-
- What do I do to make both the machines the correct value of a?
- ( My actual problem involves reading floating point numbers from a
- binary file. How do I read the correct floating point numbers
- irrespective of the machine which generated the file? )
-
- Please send me email.
- Thank you very much
- -Vinay
-
- ------Vinay Chande----chande@eng.umd.edu---------------------
- _| |_
- -------------"?"------------o('v`)o--------------"!"-------------
-
-